package javacafe.action.studybbs;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javacafe.action.Action;
import javacafe.action.ActionForward;
import javacafe.dto.member.LoginInfoDTO;
import javacafe.dto.studybbs.StudyPostDTO;
import javacafe.service.StudyBBSService;
import javacafe.serviceimple.StudyBBSServiceImpl;

public class UpdatePostAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		ActionForward forward = new ActionForward();
		forward.setTiles(false);
		
		int sp_no = Integer.parseInt(request.getParameter("sp_no"));
		int m_no = ((LoginInfoDTO)request.getSession().getAttribute("loginInfo")).getM_no();
		String content = request.getParameter("sp_content");
		String title = request.getParameter("sp_title");
		
		StudyBBSService sbbsService = StudyBBSServiceImpl.getInstance();
		StudyPostDTO postDto = new StudyPostDTO();
		postDto.setM_no(m_no);
		postDto.setSp_no(sp_no);
		postDto.setSp_content(content);
		postDto.setSp_title(title);
		sbbsService.updatePost(postDto);
		
		int sbbs_no = Integer.parseInt(request.getParameter("sbbs_no"));
		
		int study_no = Integer.parseInt(request.getParameter("study_no"));

		forward.setUrl("studybbs?command=readpost&study_no=" + study_no + "&sbbs_no=" + sbbs_no + "&sp_no=" + sp_no);
		
		return forward;
	}

}
